package Test01;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.Scanner;

public class BookManage {
//    包括获取系统信息、计算平均价格、显示当前日期以及按书名排序图书列表。
    public static Books  books = new Books();
    public static void getSystemInfo() {
        System.out.println("操作系统名称：" + System.getProperty("os.name"));
        System.out.println("操作系统版本：" + System.getProperty("os.version"));
        System.out.println("当前用户：" + System.getProperty("user.name"));
        System.out.println("java运行时环境版本：" + System.getProperty("java.version"));
    }

    public static void getCurrentDate() {
        //    显示当前日期
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前日期：" + sdf.format(date));
    }
    public static void main(String[] args) {
//        添加5本不同的书
        books.addBook(new Book("aJava编程思想1", "Bruce Eckel", LocalDate.of(2019, 1, 1), 80));
        books.addBook(new Book("dJava编程思想2", "Bruce Eckel", LocalDate.of(2019, 1, 1), 90));
        books.addBook(new Book("cJava编程思想3", "Bruce Eckel", LocalDate.of(2019, 1, 1), 89));
        books.addBook(new Book("aJava编程思想4", "Bruce Eckel", LocalDate.of(2019, 1, 1), 343));
        books.addBook(new Book("fJava编程思想5", "Bruce Eckel", LocalDate.of(2019, 1, 1), 50));
        System.out.println("----------------------图书管理系统----------------------");
        while (true){
            System.out.println("1.获取系统信息");
            System.out.println("2.计算平均价格");
            System.out.println("3.显示当前日期");
            System.out.println("4.按书名排序图书列表");
            System.out.println("5.显示图书列表");
            System.out.println("6.退出");
            System.out.print("请输入您的选择：");
            Scanner sc = new Scanner(System.in);
            int choice = sc.nextInt();
            switch (choice) {
                case 1:
                    getSystemInfo();
                    System.out.println("--------------------------------------------------");
                    break;
                case 2:
                    System.out.println("平均价格：" + books.getAveragePrice());
                    System.out.println("--------------------------------------------------");
                    break;
                case 3:
                    getCurrentDate();
                    System.out.println("--------------------------------------------------");
                    break;
                case 4:
                    books.sortBooks();
                    books.showBooks();
                    System.out.println("--------------------------------------------------");
                    break;
                case 5:
                    books.showBooks();
                    System.out.println("--------------------------------------------------");
                    break;
                case 6:
                    System.out.println("------------------------再见------------------------");
                    System.exit(0);

            }
        }
    }
}
